home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / game / shoot / ADescentSrc.lha / descent / includes / segment.h < prev    next >
C/C++ Source or Header  |  1998-03-03  |  10KB  |  275 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: /usr/CVS/descent/includes/segment.h,v $
  15.  * $Revision: 1.1.1.1 $
  16.  * $Author: nobody $
  17.  * $Date: 1998/03/03 15:12:02 $
  18.  *
  19.  * Include file for functions which need to access segment data structure.
  20.  *
  21.  * $Log: segment.h,v $
  22.  * Revision 1.1.1.1  1998/03/03 15:12:02  nobody
  23.  * reimport after crash from backup
  24.  *
  25.  * Revision 1.1.1.1  1998/02/13  20:20:26  hfrieden
  26.  * Initial Import
  27.  *
  28.  * Revision 2.1  1995/03/20  18:15:22  john
  29.  * Added code to not store the normals in the segment structure.
  30.  * 
  31.  * Revision 2.0  1995/02/27  11:26:49  john
  32.  * New version 2.0, which has no anonymous unions, builds with
  33.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  34.  * 
  35.  * Revision 1.89  1995/01/24  15:07:55  yuan
  36.  * *** empty log message ***
  37.  * 
  38.  * Revision 1.88  1994/12/12  01:04:06  yuan
  39.  * Boosted MAX_GAME_VERTS.
  40.  * 
  41.  * Revision 1.87  1994/12/11  16:18:14  mike
  42.  * add constants so we can detect too-large mines for game while in editor.
  43.  * 
  44.  * Revision 1.86  1994/12/08  15:07:29  yuan
  45.  * *** empty log message ***
  46.  * 
  47.  * Revision 1.85  1994/12/01  21:06:39  matt
  48.  * Moved plane tolerance constant to gameseg.c, the only file that used it.
  49.  * 
  50.  * Revision 1.84  1994/11/27  14:01:41  matt
  51.  * Fixed segment structure so LVLs work
  52.  * 
  53.  * Revision 1.83  1994/11/26  22:50:20  matt
  54.  * Removed editor-only fields from segment structure when editor is compiled
  55.  * out, and padded segment structure to even multiple of 4 bytes.
  56.  * 
  57.  * Revision 1.82  1994/11/21  11:43:36  mike
  58.  * smaller segment and vertex buffers.
  59.  * 
  60.  * Revision 1.81  1994/11/17  11:39:35  matt
  61.  * Ripped out code to load old mines
  62.  * 
  63.  * Revision 1.80  1994/10/30  14:12:05  mike
  64.  * rip out local segments stuff.
  65.  * 
  66.  * Revision 1.79  1994/10/27  11:33:58  mike
  67.  * lower number of segments by 100, saving 116K.
  68.  * 
  69.  * Revision 1.78  1994/08/25  21:54:50  mike
  70.  * Add macro IS_CHILD to make checking for the presence of a child centralized.
  71.  * 
  72.  * Revision 1.77  1994/08/11  18:58:16  mike
  73.  * Add prototype for Side_to_verts_int.
  74.  * 
  75.  * Revision 1.76  1994/08/01  11:04:13  yuan
  76.  * New materialization centers.
  77.  * 
  78.  * Revision 1.75  1994/07/25  00:04:19  matt
  79.  * Various changes to accomodate new 3d, which no longer takes point numbers
  80.  * as parms, and now only takes pointers to points.
  81.  * 
  82.  * Revision 1.74  1994/07/21  19:01:30  mike
  83.  * new lsegment structure.
  84.  * 
  85.  * Revision 1.73  1994/06/08  14:30:48  matt
  86.  * Added static_light field to segment structure, and padded side struct
  87.  * to be longword aligned.
  88.  * 
  89.  * Revision 1.72  1994/05/19  23:25:17  mike
  90.  * Change MINE_VERSION to 15, DEFAULT_LIGHTING to 0
  91.  * 
  92.  * Revision 1.71  1994/05/12  14:45:54  mike
  93.  * New segment data structure (!!), group, special, object, value = short.
  94.  * 
  95.  * Revision 1.70  1994/05/03  11:06:46  mike
  96.  * Remove constants VMAG and UMAG which are editor specific..
  97.  * 
  98.  * Revision 1.69  1994/04/18  10:40:28  yuan
  99.  * Increased segment limit to 1000
  100.  * (From 500)
  101.  * 
  102.  * 
  103.  */
  104.  
  105. #ifndef _SEGMENT_H
  106. #define _SEGMENT_H
  107.  
  108. #include    "types.h"
  109. #include    "fix.h"
  110. #include "vecmat.h"
  111. //#include "3d.h"
  112. //#include "inferno.h"
  113.  
  114. // Version 1 - Initial version
  115. // Version 2 - Mike changed some shorts to bytes in segments, so incompatible!
  116.  
  117. #define    SIDE_IS_QUAD    1            // render side as quadrilateral
  118. #define    SIDE_IS_TRI_02    2            // render side as two triangles, triangulated along edge from 0 to 2
  119. #define    SIDE_IS_TRI_13    3            // render side as two triangles, triangulated along edge from 1 to 3
  120.  
  121. // Set maximum values for segment and face data structures.
  122. #define    MAX_VERTICES_PER_SEGMENT    8
  123. #define    MAX_SIDES_PER_SEGMENT        6
  124. #define    MAX_VERTICES_PER_POLY        4
  125. #define    WLEFT                                0
  126. #define    WTOP                                1
  127. #define    WRIGHT                            2
  128. #define    WBOTTOM                            3
  129. #define    WBACK                                4
  130. #define    WFRONT                            5
  131.  
  132. #define    MAX_GAME_SEGMENTS                800
  133. #define    MAX_GAME_VERTICES                2800
  134.  
  135. #if defined(SHAREWARE) && !defined(EDITOR)
  136.   #define    MAX_SEGMENTS                    MAX_GAME_SEGMENTS
  137.   #define    MAX_SEGMENT_VERTICES            MAX_GAME_VERTICES
  138. #else
  139.   #define    MAX_SEGMENTS                    900
  140.   #define    MAX_SEGMENT_VERTICES            (4*MAX_SEGMENTS)
  141. #endif
  142.  
  143. //normal everyday vertices
  144.  
  145. #define    DEFAULT_LIGHTING            0            // (F1_0/2)
  146.  
  147. #ifdef EDITOR    //verts for the new segment
  148.   #define    NUM_NEW_SEG_VERTICES        8
  149.   #define    NEW_SEGMENT_VERTICES        (MAX_SEGMENT_VERTICES)
  150.   #define    MAX_VERTICES                (MAX_SEGMENT_VERTICES+NUM_NEW_SEG_VERTICES)
  151. #else        //No editor
  152.   #define    MAX_VERTICES                (MAX_SEGMENT_VERTICES)
  153. #endif
  154.  
  155. //    Returns true if segnum references a child, else returns false.
  156. //    Note that -1 means no connection, -2 means a connection to the outside world.
  157. #define    IS_CHILD(segnum) (segnum > -1)
  158.  
  159. //Structure for storing u,v,light values. 
  160. //NOTE: this structure should be the same as the one in 3d.h
  161. typedef struct uvl {
  162.     fix u,v,l;
  163. } uvl;
  164.  
  165. #ifdef COMPACT_SEGS
  166. typedef struct side {
  167.     byte        type;                                    // replaces num_faces and tri_edge, 1 = quad, 2 = 0:2 triangulation, 3 = 1:3 triangulation
  168.     ubyte        pad;                                    //keep us longword alligned
  169.     short        wall_num;
  170.     short        tmap_num;
  171.     short        tmap_num2;
  172.     uvl        uvls[4];
  173.     // vms_vector    normals[2];                        // 2 normals, if quadrilateral, both the same.
  174. } side;
  175. #else
  176. typedef struct side {
  177.     byte        type;                                    // replaces num_faces and tri_edge, 1 = quad, 2 = 0:2 triangulation, 3 = 1:3 triangulation
  178.     ubyte        pad;                                    //keep us longword alligned
  179.     short        wall_num;
  180.     short        tmap_num;
  181.     short        tmap_num2;
  182.     uvl        uvls[4];
  183.     vms_vector    normals[2];                        // 2 normals, if quadrilateral, both the same.
  184. } side;
  185. #endif
  186.  
  187. typedef struct segment {
  188.     #ifdef    EDITOR
  189.     short        segnum;                                // segment number, not sure what it means
  190.     #endif
  191.     side        sides[MAX_SIDES_PER_SEGMENT];    // 6 sides
  192.     short        children[MAX_SIDES_PER_SEGMENT];    // indices of 6 children segments, front, left, top, right, bottom, back
  193.     short        verts[MAX_VERTICES_PER_SEGMENT];    // vertex ids of 4 front and 4 back vertices
  194.     #ifdef    EDITOR
  195.     short        group;                                // group number to which the segment belongs.
  196.     #endif
  197.     short        objects;                                // pointer to objects in this segment
  198.     ubyte        special;                                // special property of a segment (such as damaging, trigger, etc.)
  199.     byte        matcen_num;                            //    which center segment is associated with.
  200.     short        value;
  201.     fix        static_light;                        //average static light in segment
  202.     #ifndef    EDITOR
  203.     short        pad;            //make structure longword aligned
  204.     #endif
  205. } segment;
  206.  
  207. #ifdef COMPACT_SEGS
  208. extern void get_side_normal(segment *sp, int sidenum, int normal_num, vms_vector * vm );
  209. extern void get_side_normals(segment *sp, int sidenum, vms_vector * vm1, vms_vector *vm2 );
  210. #endif
  211.  
  212. //    Local segment data.
  213. //    This is stuff specific to a segment that does not need to get written to disk.
  214. //    This is a handy separation because we can add to this structure without obsoleting
  215. //    existing data on disk.
  216. #define    SS_REPAIR_CENTER    0x01                //    Bitmask for this segment being part of repair center.
  217.  
  218. //--repair-- typedef struct {
  219. //--repair--     int    special_type;
  220. //--repair--     short    special_segment;                        // if special_type indicates repair center, this is the base of the repair center
  221. //--repair-- } lsegment;
  222.  
  223. typedef struct {
  224.     int        num_segments;
  225.     int        num_vertices;
  226.     short        segments[MAX_SEGMENTS];
  227.     short        vertices[MAX_VERTICES];
  228. } group;
  229.  
  230. // Globals from mglobal.c
  231. extern    vms_vector    Vertices[];
  232. extern    segment        Segments[];
  233. //--repair-- extern    lsegment        Lsegments[];
  234. extern    int            Num_segments;
  235. extern    int            Num_vertices;
  236.  
  237. extern    byte        Side_to_verts[MAX_SIDES_PER_SEGMENT][4];    // Side_to_verts[my_side] is list of vertices forming side my_side.
  238. extern    int        Side_to_verts_int[MAX_SIDES_PER_SEGMENT][4];    // Side_to_verts[my_side] is list of vertices forming side my_side.
  239. extern    char        Side_opposite[];                                    // Side_opposite[my_side] returns side opposite cube from my_side.
  240.  
  241. #define SEG_PTR_2_NUM(segptr) (Assert((unsigned) (segptr-Segments)<MAX_SEGMENTS),(segptr)-Segments)
  242.  
  243. // ----------------------------------------------------------------------------------------------------------
  244. // --------------------------  Segment interrogation functions ------------------------
  245. //       Do NOT read the segment data structure directly.  Use these functions instead.
  246. //            The segment data structure is GUARANTEED to change MANY TIMES.  If you read the
  247. //            segment data structure directly, your code will break, I PROMISE IT!
  248. //    Return a pointer to the list of vertex indices for the current segment in vp and
  249. //    the number of vertices in *nv.
  250. extern void med_get_vertex_list(segment *s,int *nv,short **vp);
  251.  
  252. //    Return a pointer to the list of vertex indices for face facenum in vp and
  253. //    the number of vertices in *nv.
  254. extern void med_get_face_vertex_list(segment *s,int side, int facenum,int *nv,short **vp);
  255.  
  256. //    Set *nf = number of faces in segment s.
  257. extern void med_get_num_faces(segment *s,int *nf);
  258.  
  259. void med_validate_segment_side(segment *sp,int side);
  260.  
  261. // Delete segment function added for curves.c
  262. extern int med_delete_segment(segment *sp);
  263.  
  264. //    Delete segment from group
  265. extern void delete_segment_from_group(int segment_num, int group_num);
  266.  
  267. //    Add segment to group
  268. extern void add_segment_to_group(int segment_num, int group_num);
  269.  
  270. // Verify that all vertices are legal.
  271. extern void med_check_all_vertices();
  272.  
  273. #endif
  274.  
  275.